import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

/** note: Submenu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    perms: ['GET /aaa','POST /bbb']     will control the page perms (you can set multiple perms)
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
    noCache: true                if true ,the page will no be cached(default is false)
  }
**/
export const constantRouterMap = [{
  path: '/redirect',
  component: Layout,
  hidden: true,
  children: [{
    path: '/redirect/:path*',
    component: () => import('@/views/redirect/index')
  }]
},
{
  path: '/login',
  component: () => import('@/views/login/index'),
  hidden: true
},
{
  path: '/auth-redirect',
  component: () => import('@/views/login/authredirect'),
  hidden: true
},
{
  path: '/404',
  component: () => import('@/views/errorPage/404'),
  hidden: true
},
{
  path: '/401',
  component: () => import('@/views/errorPage/401'),
  hidden: true
},
{
  path: '',
  component: Layout,
  redirect: 'home',
  children: [{
    path: 'home',
    component: () => import('@/views/home/index'),
    name: 'Dashboard',
    meta: {
      title: '首页',
      icon: 'dashboard',
      noCache: true
    }
  }]
}
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRouterMap
})

export const asyncRouterMap = [{
  path: '/user',
  component: Layout,
  redirect: 'noredirect',
  alwaysShow: true,
  name: 'userManage',
  meta: {
    title: '用户管理',
    icon: 'user'
  },
  children: [{
    path: 'user',
    component: () => import('@/views/user/user'),
    name: 'user',
    meta: {
      perms: ['GET /admin/user/list'],
      title: '用户列表',
      noCache: true
    }
  },
  {
    path: 'address',
    component: () => import('@/views/user/address'),
    name: 'address',
    meta: {
      perms: ['GET /admin/address/list'],
      title: '收货地址',
      noCache: true
    }
  },
  {
    path: 'collect',
    component: () => import('@/views/user/collect'),
    name: 'collect',
    meta: {
      perms: ['GET /admin/collect/list'],
      title: '用户收藏',
      noCache: true
    }
  },
  {
    path: 'footshopping',
    component: () => import('@/views/user/footShopping'),
    name: 'footshopping',
    meta: {
      perms: ['GET /admin/footprint/list'],
      title: '用户足迹',
      noCache: true
    }
  },
  {
    path: 'searchhistory',
    component: () => import('@/views/user/searchHistory'),
    name: 'searchhistory',
    meta: {
      perms: ['GET /admin/history/list'],
      title: '搜索历史',
      noCache: true
    }
  },
  {
    path: 'feedback',
    component: () => import('@/views/user/feedback'),
    name: 'feedback',
    meta: {
      perms: ['GET /admin/feedback/list'],
      title: '意见反馈',
      noCache: true
    }
  }
  ]
},

{
  path: '/mall',
  component: Layout,
  redirect: 'noredirect',
  alwaysShow: true,
  name: 'mallManage',
  meta: {
    title: '商城管理',
    icon: 'shopping'
  },
  children: [{
    path: 'region',
    component: () => import('@/views/malls/region'),
    name: 'region',
    meta: {
      title: '行政区域',
      noCache: true
    }
  },
  {
    path: 'brand',
    component: () => import('@/views/malls/brand'),
    name: 'brand',
    meta: {
      perms: ['GET /admin/brand/list', 'POST /admin/brand/create', 'GET /admin/brand/read', 'POST /admin/brand/update', 'POST /admin/brand/delete'],
      title: '品牌制造商',
      noCache: true
    }
  },
  {
    path: 'category',
    component: () => import('@/views/malls/category'),
    name: 'category',
    meta: {
      perms: ['GET /admin/category/list', 'POST /admin/category/create', 'GET /admin/category/read', 'POST /admin/category/update', 'POST /admin/category/delete'],
      title: '商品类目',
      noCache: true
    }
  },
  {
    path: 'orderform',
    component: () => import('@/views/malls/orderForm'),
    name: 'orderform',
    meta: {
      perms: ['GET /admin/order/list', 'GET /admin/order/detail', 'POST /admin/order/ordership', 'POST /admin/order/orderrefund', 'POST /admin/order/orderreply'],
      title: '订单管理',
      noCache: true
    }
  },
  {
    path: 'problem',
    component: () => import('@/views/malls/problem'),
    name: 'problem',
    meta: {
      perms: ['GET /admin/issue/list', 'POST /admin/issue/create', 'GET /admin/issue/read', 'POST /admin/issue/update', 'POST /admin/issue/delete'],
      title: '常见问题',
      noCache: true
    }
  }
  ]
},
{
  path: '/goods',
  component: Layout,
  redirect: 'noredirect',
  alwaysShow: true,
  name: 'goodsManage',
  meta: {
    title: '商品管理',
    icon: 'theme'
  },
  children: [{
    path: 'index',
    component: () => import('@/views/goods/index'),
    name: 'goodsList',
    meta: {
      perms: ['GET /admin/goods/list', 'POST /admin/goods/delete'],
      title: '商品列表',
      noCache: true
    }
  },
  {
    path: 'addgoods',
    component: () => import('@/views/goods/addgoods'),
    name: 'goodsCreate',
    meta: {
      perms: ['POST /admin/goods/create'],
      title: '商品上架',
      noCache: true
    }
  },
  {
    path: 'editgoods',
    component: () => import('@/views/goods/editgoods'),
    name: 'goodsEdit',
    meta: {
      perms: ['GET /admin/goods/detail', 'POST /admin/goods/update', 'POST /admin/goods/catAndBrand'],
      title: '商品编辑',
      noCache: true
    },
    hidden: true
  }
  ]
},
{
  path: '/activity',
  component: Layout,
  redirect: 'noredirect',
  alwaysShow: true,
  name: 'promotionManage',
  meta: {
    title: '推广管理',
    icon: 'message'
  },
  children: [{
    path: 'ad',
    component: () => import('@/views/activity/ad'),
    name: 'ad',
    meta: {
      perms: ['GET /admin/ad/list', 'POST /admin/ad/create', 'GET /admin/ad/read', 'POST /admin/ad/update', 'POST /admin/ad/delete'],
      title: '广告管理',
      noCache: true
    }
  },
  {
    path: 'coupon',
    component: () => import('@/views/activity/coupon'),
    name: 'coupon',
    meta: {
      perms: ['GET /admin/coupon/list', 'POST /admin/coupon/create', 'POST /admin/coupon/update', 'POST /admin/coupon/delete'],
      title: '优惠券管理',
      noCache: true
    }
  },
  {
    path: 'couponDetail',
    component: () => import('@/views/activity/couponDetail'),
    name: 'couponDetail',
    meta: {
      perms: ['GET /admin/coupon/list', 'GET /admin/coupon/listuser'],
      title: '优惠券详情',
      noCache: true
    },
    hidden: true
  },
  {
    path: 'subject',
    component: () => import('@/views/activity/subject'),
    name: 'subject',
    meta: {
      perms: ['GET /admin/topic/list', 'POST /admin/topic/create', 'GET /admin/topic/read', 'POST /admin/topic/update', 'POST /admin/topic/delete'],
      title: '专题管理',
      noCache: true
    }
  },
  {
    path: 'addSubject',
    component: () => import('@/views/activity/addSubject'),
    name: 'topicCreate',
    meta: {
      perms: ['POST /admin/topic/create'],
      title: '专题创建',
      noCache: true
    },
    hidden: true
  },
  {
    path: 'editSubject',
    component: () => import('@/views/activity/editSubject'),
    name: 'topicEdit',
    meta: {
      perms: ['GET /admin/topic/read', 'POST /admin/topic/update'],
      title: '专题编辑',
      noCache: true
    },
    hidden: true
  }
  ]
},
{
  path: '/system',
  component: Layout,
  redirect: 'noredirect',
  alwaysShow: true,
  name: 'sysManage',
  meta: {
    title: '系统管理',
    icon: 'system'
  },
  children: [{
    path: 'admin',
    component: () => import('@/views/system/admin'),
    name: 'admin',
    meta: {
      perms: ['GET /admin/admin/list', 'POST /admin/admin/create', 'POST /admin/admin/update', 'POST /admin/admin/delete'],
      title: '管理员',
      noCache: true
    }
  },
  {
    path: 'adminRole',
    component: () => import('@/views/system/adminRole'),
    name: 'adminRole',
    meta: {
      perms: ['GET /admin/role/list', 'POST /admin/role/create', 'POST /admin/role/update', 'POST /admin/role/delete', 'GET /admin/role/permissions', 'POST /admin/role/permissions'],
      title: '角色管理',
      noCache: true
    }
  },
  ]
},
{
  path: '/config',
  component: Layout,
  redirect: 'noredirect',
  alwaysShow: true,
  name: 'configManage',
  meta: {
    title: '配置管理',
    icon: 'peizhi'
  },
  children: [{
    path: 'mall',
    component: () => import('@/views/config/mall'),
    name: 'configMall',
    meta: {
      perms: ['GET /admin/config/mall', 'POST /admin/config/mall'],
      title: '商城信息配置',
      noCache: true
    }
  },
  {
    path: 'homeConfig',
    component: () => import('@/views/config/homeConfig'),
    name: 'homeConfig',
    meta: {
      perms: ['GET /admin/config/wx', 'POST /admin/config/wx'],
      title: '商城首页配置',
      noCache: true
    }
  },
  {
    path: 'express',
    component: () => import('@/views/config/express'),
    name: 'configExpress',
    meta: {
      perms: ['GET /admin/config/express', 'POST /admin/config/express'],
      title: '运费配置',
      noCache: true
    }
  }
  ]
},
{
  path: '/profile',
  component: Layout,
  redirect: 'noredirect',
  alwaysShow: true,
  children: [{
    path: 'password',
    component: () => import('@/views/rePassword/index'),
    name: 'password',
    meta: {
      title: '修改密码',
      noCache: true
    }
  }],
  hidden: true
},
{
  path: '*',
  redirect: '/404',
  hidden: true
}
]
